export default {
    XianMu: [{
        title: '现场管理',
        item: [{
                badge: 0,
                label: '安全',
                switch: false,
                icon: require('../assets/xanquan.png')
            }, {
                badge: 0,
                switch: false,
                label: '质量',
                icon: require('../assets/xzhilian.png')
            }, {
                badge: 0,
                switch: false,
                label: '实测实量',
                icon: require('../assets/xscsl.png')
            }
            // , {
            //     badge: 0,
            //     label: '记工',
            //     icon: require('../assets/xjg.png')
            // },
        ]
    }, {
        title: '项目资料',
        item: [{
                switch: false,
                label: '图纸',
                icon: require('../assets/xtuzhi.png')
            }, {
                switch: false,
                label: '文件',
                icon: require('../assets/xwenjian.png')
            }, {
                switch: false,
                label: '物资',
                icon: require('../assets/xwuzi.png')
            },
        ]
    },{
        title: '协同办公',
        item: [{
                switch: false,
                label: '施工任务单',
                icon: require('../assets/xsgrwd.png')
            } 
        ]
    }],
    GonZuo: {
        gonZuoItem: [
            {badge: 0, label: '负责的', icon: require('../assets/fuzede.png')},
            {badge: 0, label: '分派的', icon: require('../assets/fenpaide.png')},
            {badge: 0, label: '参与的', icon: require('../assets/canyude.png')},
            {badge: 0, label: '新建', icon: require('../assets/xianjiade.png')},
        ]
    },
    YinYon: [{
        title: '办公管理',
        item: [{
                badge: 0,
                label: '公告',
                switch: false,
                icon: require('../assets/ygg.png')
            }, {
                badge: 0,
                label: '考勤',
                switch: false,
                icon: require('../assets/ykq.png')
            }, {
                badge: 0,
                label: '云盘',
                switch: false,
                icon: require('../assets/yyp.png')
            },
        ]
    }, {
        title: '项目管理',
        item: [{ 
                label: '施工日志',
                switch: false,
                icon: require('../assets/yrz.png')
            }, {
                badge: 0,
                label: '安全',
                switch: false,
                icon: require('../assets/yaq.png')
            }, { 
                label: '质量',
                switch: false,
                icon: require('../assets/yzl.png')
            }, { 
                label: '日报',
                switch: false,
                icon: require('../assets/yrb.png')
            }, { 
                label: '计划',
                switch: false,
                icon: require('../assets/yjh.png')
            }, { 
                label: '模型浏览',
                switch: false,
                icon: require('../assets/moxin.png')
            }, { 
                label: '记工',
                switch: false,
                icon: require('../assets/yjg.png')
            }, { 
                label: '物资',
                switch: false,
                icon: require('../assets/ywz.png')
            }, { 
                label: '文件',
                switch: false,
                icon: require('../assets/ywj.png')
            }, { 
                label: '材料',
                switch: false,
                icon: require('../assets/ycl.png')
            }, {
                badge: 0,
                label: '机械',
                switch: false,
                icon: require('../assets/yjx.png')
            }, {
                label: '施工任务单',
                switch: false,
                icon: require('../assets/xsgrwd.png')
            }, { 
                label: '实测实量',
                switch: false,
                icon: require('../assets/yscsl.png')
            } 
        ]
    }, {
        title: '公司管理',
        item: [{ 
                label: '预算',
                switch: false,
                icon: require('../assets/yys.png')
            }, { 
                label: '采购',
                switch: false,
                icon: require('../assets/ycg.png')
            },  { 
                label: '合同',
                switch: false,
                icon: require('../assets/yht.png')
            },  { 
                label: '报销',
                switch: false,
                icon: require('../assets/ybx.png')
            } 
        ]
    },{
        title: '统计管理',
        item: [{ 
                label: '考勤统计',
                switch: false,
                icon: require('../assets/ykqtj.png')
            }, { 
                label: '工作统计',
                switch: false,
                icon: require('../assets/ygztj.png')
            }, { 
                label: '物资统计',
                switch: false,
                icon: require('../assets/ywztj.png')
            }, { 
                label: '记工统计',
                switch: false,
                icon: require('../assets/yjgtj.png')
            } 
        ]
    }],
    html: `
    <body style="padding: 0; margin: 0">
    <div id='box'>  
        <canvas id='canvas_image'></canvas>
        <canvas id='canvas_point' style="position: absolute; left: 0; top: 0"></canvas>
    </div>
    <script> 
        //指令 
        //{ key: 'drawPic', pic: '', p}
        //{ key: 'drawPoints', value: [{},{}]} 
        //{ key: 'drawSelect', value: {}} //重画 select point
        //{ key: 'drawAppend', value: {}}
        //{ key: 'drawOne' }
        (function() {
            window.postMessage = function(data) {
                window.ReactNativeWebView.postMessage(data);
            };
        })();  
        document.addEventListener('message', function(msg) {  
            var instruction = JSON.parse(msg.data) 
            switch (instruction.key) {
                case 'drawPic': 
                    drawPic(instruction.value)
                    break
                case 'drawPoints': 
                    drawPoints(instruction.value) 
                    break
                case 'drawBooms':
                    drawBooms(instruction.value) 
                    break
                case 'drawSelect':
                    drawSelect(instruction.value)
                    break
                case 'drawAppend': 
                    drawAppend(instruction.value)
                    break
                case 'postList':
                    postList(instruction.value)
                    break
                case 'drawOne':
                    drawOne()
                    break
            } 
        });  
        var rangeX = rangeY = 35, pointList
        function postList(list) {
            pointList = list
        }
        function drawPic(url) {
            var canvas_image = document.getElementById('canvas_image')
            var canvas_point = document.getElementById('canvas_point')
 
            var ctx = canvas_image.getContext("2d")
            var img = new Image()
            img.src = url
            img.onload = function(e) {    
                var newHeight =  (window.screen.width * 2.73) / img.width * img.height 
                canvas_point.width = canvas_image.width =  window.screen.width * 2.73
                canvas_point.height = canvas_image.height =  newHeight

                ctx.drawImage(img, 0, 0, canvas_image.width, newHeight) 
                window.postMessage('drawPicOver')
            }
        }
        function drawBooms(list) { 
            pointList = list
            draw(list, 'boom')
            var canvas_point = document.getElementById('canvas_point')
            canvas_point.addEventListener('click', function(e) { 
                var _ins = []
                for(var p of list) {
                    if (p.x - rangeX < e.pageX && p.x + rangeX > e.pageX && p.y - rangeY < e.pageY && p.y + rangeY > e.pageY)
                        _ins.push(p)
                }
                if (_ins.length) { 
                    window.postMessage(JSON.stringify(_ins))
                }
            })
        }
        function drawPoints(list) { 
            pointList = list
            draw(list)
            var canvas_point = document.getElementById('canvas_point')
            canvas_point.addEventListener('click', function(e) { 
                var _ins = []
                for(var p of list) {
                    if (p.x - rangeX < e.pageX && p.x + rangeX > e.pageX && p.y - rangeY < e.pageY && p.y + rangeY > e.pageY)
                        _ins.push(p)
                }
                if (_ins.length) { 
                    window.postMessage(JSON.stringify(_ins))
                }
            })
        }
        var prePoint = null
        function drawSelect(point) { 
            draw(pointList, null, true, point)
        }
        function drawAppend(point) { 
            pointList.push(point)
            draw(pointList, null, true, point)
        }
        function drawOne() {
            var canvas_point = document.getElementById('canvas_point')
            canvas_point.addEventListener('click', function(e) { 
                var point = {
                    x: e.pageX - 15,
                    y: e.pageY - 35
                } 
                draw([point])
                window.postMessage(JSON.stringify(point))
            })
        }
        function isYiCe(point) {
            if (point.pointCheckList && point.pointCheckList.length) {
                for (var i = 0; i < point.pointCheckList.length; i ++) {
                    if (point.pointCheckList[i].dataLogList && point.pointCheckList[i].dataLogList.length === 0) {
                        return false
                    }
                }
            }
            return true
        }
        function draw(points, imgUrl, clear, point2) {
            points = points || [] 
            clear = clear == void 0 ? true : false
            var canvas_point = document.getElementById('canvas_point')
            var ctx = canvas_point.getContext("2d")
            ctx.font="30px Georgia"
            if (true)
                ctx.clearRect(0, 0, canvas_point.width, canvas_point.height)  

            var img = new Image(), imgSelect = new Image(), imgYiCe = new Image(), imgBoom = new Image()
            imgSelect.src = ''
            imgYiCe.src = ''
            img.src = ''
            imgBoom.src = ''

            img.onload = function(e) { 
                for(var point of points) {   
                    if (imgUrl == 'boom') {
                        ctx.drawImage(imgBoom, point.x - 12, point.y - 20, 62, 62)
                    } else if (point2 && point2.label == point.label) {  
                        ctx.drawImage(imgSelect, point.x - 25, point.y - 32, 88, 88)
                    } else if (isYiCe(point)) { 
                        ctx.drawImage(imgYiCe, point.x - 12, point.y - 20, 62, 62)
                    } else { 
                        ctx.drawImage(img, point.x - 12, point.y - 20, 62, 62)
                    }
                    ctx.fillText(point.label || '', point.x + 50, point.y + 15)
                }
            }
        } 
    </script>
</body>
    `
}